<?php
/**
 * 筛选模块
 *
 * 筛选模块controller
 *
 * @author    zhouchao <zhouchao@yunys.com.cn>
 * @copyright 2016 QuanZhouYunYiShang Inc.
 */
namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\SearchService\SearchService;
use Illuminate\Support\Facades\Response;

use App\Services\UserService\UserTool;
use App\Services\ProductTempService\ProductTempTool;
use App\Services\ProductsService\ProductsService;

class SearchController extends Controller
{
    protected $searchService;
    public function __construct(SearchService $searchService)
    {
        $this->searchService = $searchService;
    }

    public function postSearch(Request $request){
        $product_temp_category_id = intval($request->input('product_temp_category_id'));
        $app_id = intval($request->input('app_id'));
        $result = $this->searchService->get_search_arr($product_temp_category_id,$app_id);
        return Response::json($result);
    }

    /**
     * 模糊搜索用户和作品
     * @Author    zhouchao
     * @DateTime  2017-03-13
     * @copyright 2017 QuanZhouYunYiShang Inc.
     * @license   [license]
     * @version   [version]
     * @param     Request
     * @param     UserTool
     * @param     ProductTempTool
     * @param     ProductsService
     * @return    mixed
     */
    public function postFuzzy(Request $request, UserTool $user_tool, ProductTempTool $product_temp_ser, ProductsService $product_ser)
    {
        $type = intval($request->input('type'));
        $per_page = intval($request->input('per_page')) > 0 ? intval($request->input('per_page')) : 10;
        $conditions = json_decode($request->input('conditions'),true);
        $result = $this->searchService->search_for_type($type, $conditions, $user_tool, $product_temp_ser, $product_ser, $per_page);
        return Response::json($result);
    }
}
